package com.zs4sdk.entity;

import com.common.library.entity.JSONResultEntity;
import com.common.library.util.Helper;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Jancy on 16/2/15.
 */
public class MessageResultEntity extends JSONResultEntity {
    public static final String NUM = "num";
    public static final String TIMESTAMP = "timestamp";
    private int num;
    private String timestamp;

    /**
     * 构造方法
     * @param json
     */
    public MessageResultEntity(JSONObject json){
        this.fromJSON(json);
    }

    //#region Override方法
    @Override
    public JSONObject toJSON() {
        JSONObject result = super.toJSON();
        try {
            result.put(NUM, this.num);
            result.put(TIMESTAMP,this.timestamp);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public void fromJSON(JSONObject json) {
        super.fromJSON(json);
        if (Helper.isNotEmpty(json)) {
            this.num = json.optInt(NUM);
            this.timestamp = json.optString(TIMESTAMP);
        }
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }
}
